package com.yenlien.traceyun.business.dao;

import com.yenlien.traceyun.business.entity.ScanRecord;
import com.yenlien.traceyun.webase.dao.BaseJpaDao;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-12-30
 * @description:
 **/
public interface ScanRecordDao extends BaseJpaDao<ScanRecord> {

    public List<ScanRecord> findByCode(String code, Sort sort);

    @Query(value = "SELECT * FROM t_scan_record WHERE code = ?1 AND company_id = ?2 ORDER BY createtime DESC", nativeQuery = true)
    List<ScanRecord> findByCodeAndCompanyId(String code, String companyId);

    List<ScanRecord> findByCreatetimeBetweenAndCompanyIdIn(Date createtime, Date createtime2, List<String> companyId);

    @Query(value = "select distinct address from t_scan_record where company_id = ?1", nativeQuery = true)
    List<String> findAddress(String companyId);

    List<ScanRecord> findByAddress(String address);

    List<ScanRecord> findByCompanyIdAndAddressLike(String company, String address);

    @Query(value = "select count(code) from t_scan_record where company_id=?1", nativeQuery = true)
    int scanCode(String companyId);

    @Query(value = "select address from t_scan_record where company_id=?1", nativeQuery = true)
    List<Map<String, Object>> scanAddress(String companyId);

    @Query(value = "select  count(address) from t_scan_record where address LIKE CONCAT('%',?,'%')", nativeQuery = true)
    int scanAddressSum(String addressStr);


}